export default{
    namespaced:true,
    //数据
    state:()=>({
      address:JSON.parse(uni.getStorageSync('address') || '{}'),
      token:uni.getStorageSync('token') || '',
      userInfo:JSON.parse(uni.getStorageSync('userInfo') || '{}'),
      redirectInfo:null,
    }),
    //方法
    mutations:{
      updateToken(state,token){
        state.token = token;
        this.commit('m_user/saveToken');
      },
      updateRedirectInfo(state,redirectInfo){
        state.redirectInfo = redirectInfo;
        this.commit('m_user/redirectInfo');
      },
      updateUserInfo(state,userInfo){
        state.userInfo = userInfo;
        this.commit('m_user/saveUserInfo');
      },
      updateAddress(state,address){
        state.address = address;
        this.commit('m_user/saveAddress');
      },
      saveAddress(state){
        uni.setStorageSync('address',JSON.stringify(state.address));
      },
      saveUserInfo(state){
        uni.setStorageSync('userInfo',JSON.stringify(state.userInfo));
      },
      saveToken(state){
        uni.setStorageSync('token',JSON.stringify(state.token));
      },
      redirectInfo(state){
        uni.setStorageSync('redirectInfo',JSON.stringify(state.redirectInfo));
      },
    },
    getters:{
      addstr(state) {
          if (!state.address.provinceName) return ''
          // 拼接 省，市，区，详细地址 的字符串并返回给用户
          return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
        }
    }
    
}